package br.com.rocks.rs232;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class ArrayAdapterBalao extends ArrayAdapter<DadosDaConversa> {
	private Context context;

	public ArrayAdapterBalao(Context context) {
		super(context, R.layout.balao_list_recebido, R.id.textViewMensagens);
		this.context = context;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		DadosDaConversa dadosDaConversa = getItem(position);

		View viewBalao = convertView;
		if (!dadosDaConversa.isRecebida()) {
			viewBalao = LayoutInflater.from(context).inflate(R.layout.balao_list_enviado, parent, false);
		} else {
			viewBalao = LayoutInflater.from(context).inflate(R.layout.balao_list_recebido, parent, false);
		}
		View view = super.getView(position, viewBalao, parent);

		((TextView) view.findViewById(R.id.textViewMensagens)).setText(dadosDaConversa.getMensagem());
		((TextView) view.findViewById(R.id.textViewHoras)).setText(dadosDaConversa.getDataFormatada());

		return view;
	}
}
